﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KCMS.BusinessLogic.Interfaces;
using KCMS.DataAcsess.Interfaces;
using StructureMap;
using AutoMapper;
using KCMS.BusinessLogic.Models;

namespace KCMS.BusinessLogic.Engine
{
    public class PageCategoryService:IPageCategoryService
    {
        private IPageCategoryManager pgm = ObjectFactory.GetInstance<IPageCategoryManager>();
        //private IPictureService pictureSevice = ObjectFactory.GetInstance<IPictureService>();
        public Models.PageCategory getById(Guid id)
        {
            DataAcsess.Entitys.PageCategoryEntity pageCategoryEntity = pgm.getById(id);
            return Mapper.Map<DataAcsess.Entitys.PageCategoryEntity, Models.PageCategory>(pageCategoryEntity);
        }
        public Models.PageCategory getByCodeIndex(String code)
        {


            var pageCategoryEntity = (from t in pgm.getAll()
                              where (t.Code.Equals(code))
                              select t).SingleOrDefault();
            return Mapper.Map<DataAcsess.Entitys.PageCategoryEntity, Models.PageCategory>(pageCategoryEntity);
        }

        public IEnumerable<Models.PageCategory> getAll()
        {
            return Mapper.Map<IEnumerable<DataAcsess.Entitys.PageCategoryEntity>, IEnumerable<Models.PageCategory>>(pgm.getAll());

        }

        public void update(PageCategory pageCategory)
        {
            pgm.update(Mapper.Map<PageCategory, DataAcsess.Entitys.PageCategoryEntity>(pageCategory));
        }


        public void save(PageCategory pageCategory)
        {
            pgm.save(Mapper.Map<PageCategory, DataAcsess.Entitys.PageCategoryEntity>(pageCategory));
        }


        public void delete(Guid id)
        {
            pgm.delete(id);
        }
    }
}
